﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Data.EntityClient;
using System.Data.Metadata.Edm;
using System.Reflection;
using System.Data.Objects;
using SharpHsql.Data.Client;

namespace WinTest {
    static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {

            //InitData();
            //var st = new System.Diagnostics.Stopwatch();

            //st.Start();

            //LinqQuery();

            //st.Stop();
            var s = typeof(SharpHsql.Data.Entity.SharpHsqlProviderServices).FullName;
            //Console.WriteLine(st.ElapsedMilliseconds);
            //var p = Type.GetType("SharpHsql.Data.Entity.SharpHsqlProviderServices, SharpHsql.Data.Entity, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null");

            //var space = new MetadataWorkspace(new string[]{ Application.StartupPath},new Assembly[]{ typeof(Program).Assembly});
            //var connection = new EntityConnection(space,new SharpHsqlConnection("database=.;uid=sa;pwd="));
            //var context = new ObjectContext(connection);
            //var q = context.CreateObjectSet<Product>("Entities.Products").FirstOrDefault();

            var context = new northwindEntities();
            var db = new SharpHsql.Data.Database("northwind");
            var channel = db.Connect("SA", string.Empty);
            var script = @"Create Table customers ( CustomerID varchar(50) PRIMARY KEY ,CompanyName varchar(50),ContactName varchar(50),
                                    ContactTitle varchar(50),Address varchar(50),City varchar(50) ,Region Varchar(50),PostalCode Varchar(50),Country Varchar(50),
                                   Phone varchar(30),Fax varchar(10) )";
            var rs =  db.Execute(script, channel);
            for (int i = 0; i < 100; i++)
            {
                script = "Insert into customers (CustomerID) values ('C" + i + "')";
                db.Execute(script, channel);
            }
            db.Dispose();
                                    
            var q = context.Customers1.OrderBy(c=>c.ContactName).Skip(10).Take(1).ToList();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        static void Test() {
 

        }
        //static void LinqQuery()
        //{
        //    var q = from p in products
        //            join c in categories on p.CategoryId equals c.ID
        //            join od in orderDetails on p.ID equals od.ProductId
        //            join o in orders on od.OrderId equals o.ID
        //            where o.ID > 5 && o.ID < 100
        //            select new { p.ID, od.Count };

        //    var count = q.Count();

        //}

        //static List<Product> products = new List<Product>();
        //static List<OrderDetails> orderDetails = new List<OrderDetails>();
        //static List<Orders> orders = new List<Orders>();
        //static List<Category> categories = new List<Category>();

        //static void InitData()
        //{

        //    var rd = new Random();

        //    for (int i = 1; i < 100001; i++)
        //    {
        //        products.Add(new Product() { 
        //            ID= i,
        //            Name = "Product_" + i,
        //            Price = rd.Next(10,1000)/10,
        //            CategoryId = rd.Next(1,100)
        //        });
        //    }

        //    for (int i = 1; i < 10001; i++)
        //    {
        //        orders.Add(new Orders()
        //        {
        //            ID = i,
        //            OrderDate = DateTime.Now,
        //            CustomerId = rd.Next(1,10000)
        //        });
        //    }

        //    for (int i = 1; i < 201; i++)
        //    {
        //        categories.Add(new Category() { ID = i, Name = "Category_" + i });
        //    }

        //    for (int i = 1; i < 50001; i++)
        //    {
        //        orderDetails.Add( new OrderDetails(){ ID= i,OrderId = rd.Next(1,10000),ProductId = rd.Next(1,100000), Count = rd.Next(2,100)});
        //    }
        //}
    }
}
